import userApiClient from '../../axios/user';
import type { 
  SendCodeRequest,
  FinalizeRegisterRequest,
  RegisterResponse,
  ApiResponse,
  LoginRequest,
  LoginResponse,
  UserInfo,
  RequestPasswordResetRequest,
  ResetPasswordRequest,
  UserDetailInfo
} from '../../dto/user';

// 用户相关API
export const userApi = {
  sendCode: (data: SendCodeRequest): Promise<ApiResponse<{code: string}>> => {
    return userApiClient.post('/user/send-code', data);
  },
  finalizeRegister: (data: FinalizeRegisterRequest): Promise<RegisterResponse> => {
    return userApiClient.post('/user/register/finalize', data);
  },
  login: (data: LoginRequest): Promise<LoginResponse> => {
    return userApiClient.post('/user/login', data);
  },
  logout: (): Promise<ApiResponse<string>> => {
    return userApiClient.post('/user/logout');
  },
  requestPasswordReset: (data: RequestPasswordResetRequest): Promise<ApiResponse<Record<string, never>>> => {
    return userApiClient.post('/user/password/request-reset', data);
  },
  resetPassword: (data: ResetPasswordRequest): Promise<ApiResponse<Record<string, never>>> => {
    return userApiClient.post('/user/password/reset', data);
  },
  getUserInfoById: (id: number): Promise<ApiResponse<UserDetailInfo>> => {
    return userApiClient.get(`/user/getUserInfo/${id}`);
  },
  getCurrentUser: (): Promise<ApiResponse<{userInfo: UserInfo}>> => {
    return userApiClient.get('/user/current');
  },
  updateUserInfo: (data: Partial<UserDetailInfo>): Promise<ApiResponse<UserDetailInfo>> => {
    console.log('更新用户信息，请求数据:', data);
    return userApiClient.post('/user/updateUserInfo', {
      id: data.id,
      username: data.username,
      avatar: data.avatar,
      signature: data.signature
    });
  }
}; 
